//
//  EMInputTextField.m
//  LoginAndReg
//
//  Created by fortsven on 14/12/23.
//  Copyright (c) 2014年 hoperun. All rights reserved.
//

#import "EMInputTextField.h"

@implementation EMInputTextField
{
    UIView *leftView;
}
- (void)setTextFieldMode: (NSInteger)mode
{
    if (mode == EMInputTextFieldModeLogoAndText) {
        [self drawEMLogoAndTextField];
    } else if (mode == EMInputTextFieldModeTextAndIcon) {
        [self drawEMTextFieldAndRightIcon];
    } else {
        [self drawEMTextField];
    }
}

- (void)drawEMTextField
{
    self.inputTextField = [[UITextField alloc] init];
    self.inputTextField.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    self.inputTextField.layer.borderColor = RGB(112, 179, 81).CGColor;
    self.inputTextField.layer.borderWidth = 1;
    self.inputTextField.layer.cornerRadius = 4;
    self.inputTextField.font = [UIFont fontWithName:HEITILIGHT size:14];
    self.inputTextField.placeholder = _placeholderText;
    leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, self.inputTextField.frame.size.height)];
    self.inputTextField.leftView = leftView;
    self.inputTextField.leftViewMode = UITextFieldViewModeAlways;
    [self addSubview:self.inputTextField];
}

- (void)drawEMLogoAndTextField
{
    [self drawEMTextField];
    leftView.frame = CGRectMake(0, 0, self.frame.size.height + 10, self.inputTextField.frame.size.height);
    UIImageView *logoImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:_logoName]];
    logoImage.frame = CGRectMake(10, 10, self.frame.size.height - 20, self.frame.size.height - 20);
    [leftView addSubview:logoImage];
    UIImageView *sepLineImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_输入框_分割线"]];
    sepLineImage.frame = CGRectMake(self.frame.size.height, 10, 2, self.frame.size.height - 20);
    [leftView addSubview:sepLineImage];
}

- (void)drawEMTextFieldAndRightIcon
{
    [self drawEMTextField];
    self.inputTextField.text = _text;
    UIImageView *sepLineImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_菜单_展开"]];
    sepLineImage.frame = CGRectMake(self.frame.size.width - 35, 10, self.frame.size.height - 15, self.frame.size.height - 20);
    [leftView addSubview:sepLineImage];
    
}
@end
